<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li ><a href="{:url('Classes/index')}">班级列表</a></li>
        <li class="active"><a href="">班级详情</a></li>
    </ul>
    <form class="js-ajax-form col-lg-10 col-md-12" action="" method="get">
        <h3>{$class_name}</h3>

        <div class="table-actions" style="margin-top:20px;">
            <if condition="$is_and_class==1">
                <div class="form-group col-xs-2">
                    <select class="form-control"  name="select" id="">
                        <option value="">选择班级</option>
                        <foreach name="class_all" item="vo">
                            <option value="{$vo.id}">
                                {$vo.name}
                            </option>
                        </foreach>
                    </select>
                </div>

            <button class="btn btn-danger btn-sm js-ajax-submit" type="submit"
                    data-action="{:url('classes/insert_class')}" data-subcheck="true" data-msg="您确定合班吗？" style="margin-top:5px;">
                批量合班
            </button>
            </if>
            <a class="btn btn-primary btn-sm tan" style="margin-top:5px;">导出列表</a>
        </div>
        <table class="table table-hover table-bordered table-list">
            <thead>
                <tr>
                    <th width="15">
                        <label>
                            <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                        </label>
                    </th>
                    <th class="col-xs-1">生日</th>
                    <th class="col-xs-1">姓名</th>
                    <th class="col-xs-1">性别</th>
                    <th class="col-xs-1">学校</th>
                    <th class="col-xs-2">手机号</th>
                    <th class="col-xs-1">学号</th>
                    <th class="col-xs-1">入班时间</th>
                    <th class="col-xs-1">位置状态</th>
                    <!--<th class="col-xs-1">学员状态</th>-->
                    <th class="col-xs-1">回访记录</th>
                </tr>
            </thead>
            <foreach name="data" item="vo">
                <tr>
                    <td>
                        <if condition="$vo.class_id eq $vo.old_class_id && $vo.csstatus=1">
                            <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                                   value="{$vo.id}" title="ID:{$vo.id}">
                            <input type="hidden" value="{$vo.old_class_id}" name="old_id[]">
                            <input type="hidden" value="{$vo.tid}" name="tid[]">

                            <else/>
                        </if>
                    </td>
                    <td>{$vo.birthday|date='Y-m-d',###}</td>
                    <td>{$vo.tname}</td>
                    <td>
                        <if condition=" $vo.tgender eq 1">
                            男
                            <elseif condition=" $vo.tgender eq 2">
                                女
                            </elseif>
                            <else />
                          保密
                        </if>
                    </td>

                    <td>{$vo.school_name}</td>
                    <td>{$vo.mobile}</td>
                    <td>{$vo.tcode}</td>

                    <td>{$vo.insert_class_time|date='Y-m-d',###}</td>
                    <td>
                        <if condition="$vo.class_id eq $vo.old_class_id && $vo.csstatus=1">
                            未选座
                            <elseif  condition="$vo.class_id neq $vo.old_class_id && $vo.csstatus==1">
                                    新班未选座
                            </elseif>
                            <else/>
                            已选座
                        </if>
                    </td>

                    <!--<td>-->

                        <!--<if condition="isset($is_and_class) &&  $vo.csstatus eq 1 ">-->
                            <!--正常-->
                            <!--<elseif  condition="isset($is_and_class)  && !empty($is_and_class) && $vo.csstatus==0">-->
                                <!--已离班-->
                            <!--</elseif>-->
                            <!--<else/>-->
                            <!--正常-->
                        <!--</if>-->
                    <!--</td>-->
                        <td>
                            <a class="visit_show">展开查看</a>
                            <a style="text-decoration: none;">
                                <span class="glyphicon glyphicon-chevron-down"></span>
                            </a>
                             |
                            <a class="visit_add">
                                添加
                                <input type="hidden"  value="{$vo.tid}">
                                <input type="hidden"  value="{$vo.class_id}">
                            </a>

                        </td>
                </tr>
                <tr class="visit_tr">
                    <td>
                        <!--占位-->
                    </td>
                    <td colspan="8" style="padding:8px 0px;">
                        <table class="table table-hover table-bordered table-list">
                                <tr>
                                    <th class="col-xs-2">回访标题</th>
                                    <th class="col-xs-1">回访老师</th>
                                    <th class="col-xs-6">回访内容</th>
                                    <th class="col-xs-1">回访时间</th>
                                    <th class="col-xs-2">操作</th>
                                </tr>
                            <foreach name="$vo.visit" item="x">
                                <tr>
                                    <td>{$x.title}</td>
                                    <td>{$x.teacher_id}</td>
                                    <td>{$x.content}</td>
                                    <td>{:date('Y-m-d',$x.create_time)}</td>
                                    <td>
                                        <a class="visit_delete" data="{$x.id}">删除</a>
                                    </td>
                                </tr>
                            </foreach>
                        </table>
                    </td>
                </tr>
            </foreach>
            <!--并班的班级不存在了，它也要并班了-->
            <if condition="isset($arr)">
            <tr>
                        <td colspan="9">
                          {$arr}
                        </td>
            </tr>
            </if>
        </table>
        </form>
</div>

<div id="visit_add_msg" >
    <form action="{:url('Classes/addVisitPost',array('id'=>$id))}" method="post" class="well row" style="margin:0px;"><!--form-horizontal -->
        <!--<input type="hidden" name="id" value="{$id}">-->
        <input type="hidden" name="class_id" value="">
        <input type="hidden" name="student_id" value="">
        <label class="form-group" for="">
            输入回访标题:<span class="form-required">*</span>
            <input class="form-control" type="text" name="title"
            id="title"  value="" placeholder="请输入标题" required="required">
        </label>
        <label class="form-group" for="">
            输入回访次数:<span class="form-required">*</span>
            <select name="num" class="form-control" id="visit_num">
                <option value="1">1</option>
                <option value="2">2</option>
                <option value="3">3</option>
                <option value="4">4</option>
                <option value="5">5</option>
                <option value="6">6</option>
                <option value="7">7</option>
                <option value="8">8</option>
                <option value="9">9</option>
                <option value="10">10</option>
            </select>
        </label>
        <label class="form-group" for="">
            输入回访老师:<span class="form-required">*</span>
            <input class="form-control" type="text" name="teacher_id" required="required" placeholder="请输入回访老师">
        </label>
        <label  class="form-group" for="">
            输入回访内容:<span class="form-required">*</span>
            <textarea class="form-control" id="content" name="content" cols="40" rows="5"  placeholder="请输入回访内容" required="required"></textarea>
        </label>
        <input type="submit" id="subimt" style="display:none;" class="btn btn-primary ">
    </form>
</div>

<div id="tan" style="display:none">
    <form action="{:url('Classes/excel')}" method="post" class="well row" style="margin:0;">
        <label  class="form-group col-xs-12" for="">
            <input type="hidden" name="id" value="{$id}">
            <input type="number" name="num1" value="" id="num1">
        </label>
    </form>
</div>

<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/layer/layer.js"></script>
<script>
    <!--并班后,学生进行选班操作-->
    $('body').on('click','.enter_class',function() {
        var selectedCategoriesId = $(this).attr('data_ct_id');

        $.ajax({
            'url':"{:url('classes/Classes/pre_class')}",
            'data':{'ids':selectedCategoriesId},
            'success':function(data)
            {
                data=eval(data);
                classroom=$(".select_class");
                classroom.find("option").remove();
                $("<option value='0'>选择班级</option>").appendTo(classroom);
                for(var i in data)
                {
                    $("<option value="+data[i].id+">"+data[i].name+"</option>").appendTo(classroom);
                }

            },
            'error':function()
            {
                layer.msg(data.msg, {icon: 5});
            }
        })

    })
    $('body').on('click','.insert_class',function() {
        var selectedCategoriesId = $(this).siblings('.select_class').val();
        var tid=$(this).siblings('.enter_class').attr('data-id');
        var cid=$(this).siblings('.enter_class').attr('data-id1');
        $(this).attr('attr_id',selectedCategoriesId);
        $.ajax({
            'url':"{:url('classes/Classes/insert_class')}",
            'data':{'ids':selectedCategoriesId,'tid':tid,'cid':cid},
            'success':function(data)
            {
                layer.msg('成功', {icon: 6});
                location.reload();
            },
            'error':function()
            {
                layer.msg('失败', {icon:5});
            }
        })
    })
    $('body').on('click','.visit_show',function(){
        var $this=$(this);
        var $target=$(this).parent().parent().next('tr');
        $target.toggle(150);

        if( $this.text() == '展开查看') {
            $this.text('收起记录');
            $this.next('a').children('span')
                .addClass('glyphicon-chevron-up')
                .removeClass('glyphicon-chevron-down');
        }else{
            $this.text('展开查看');
            $this.next('a').children('span')
                .addClass('glyphicon-chevron-down')
                .removeClass('glyphicon-chevron-up');
        }

    })

    $('body').on('click','.visit_add',function () {
        var stuID=$(this).children('input:first').val();
        var classID=$(this).children('input:eq(1)').val();
        $("[name='class_id']").val(classID);
        $("[name='student_id']").val(stuID);
        layer.open({
            type: 1,
            btn: ['提交'],
            title: '添加回访记录',
            content: $('#visit_add_msg'),
            yes: function (index,layero) {
//                $('#subimt').click(function(){
                var $title=$("[name='title']").val();
                var $teacher=$("[name='teacher_id']").val();
                var $content=$("[name='content']").val();
                var $num=$("[name='num']").val();

                $('input').blur(function () {
                    $title=$("[name='title']").val();
                    $teacher=$("[name='teacher_id']").val();
                    $content=$("[name='content']").val();
                    $num=$("#visit_num").find('option selected').val();

                })

                $.ajax({
                        "url":"{:url('Classes/addVisitPost',array('id'=>$id))}" ,
                        "data":{
                            "class_id":$("[name='class_id']").val(),
                            "student_id":$("[name='student_id']").val(),
                            "title":$title,
                            "teacher_id":$teacher,
                            "content":$content,
                            'num':$num,

                        },
                        "beforeSend":function () {
                            if(!$title || !$teacher || !$content){
                                layer.msg('请输入必填字段');
                                return false;
                            }
                        },
                        'success':function(data)
                        {
                            layer.msg(
                                '添加成功', {icon: 6,time:1500},function () {location.reload();}
                            );
                        },
                        'error':function()
                        {
                            layer.msg('添加失败', {icon:5,time:1500},function () {location.reload();});
                        }
                })
            }
        })
    })

    $('body').on('click','.visit_delete',function () {
        var $href=$(this).attr('data');
        $.ajax({
            "url": "{:url('classes/classes/deleteVisit')}",
            "data":{"id":$href},
            "success":function () {
                layer.msg(
                    '删除成功', {icon: 6,time:1500},function () {location.reload();}
                );
            },
            'error':function()
            {
                layer.msg('删除失败', {icon:5,time:1500});
            }
        })
    })
$(".tan").click(function()
{
    $.ajax(function()
    {

    })
    layer.open({
        type: 1,
        btn: ['提交'],
        title: '第几次回访',
        content: $('#tan'),
        yes: function (index,layero) {
            $('#tan form').submit();
        }
    })
})
</script>
</body>
</html>
